var Timer = (function () {
    function Timer() {
        this.timerId = 0;
        this.timers = [];
    }
    Timer.prototype.add = function (fn) {
        this.timers.push(fn);
    };
    Timer.prototype.start = function () {
        if (this.timerId)
            return;
        this.runNext();
    };
    Timer.prototype.runNext = function () {
        if (this.timers) {
            this.currTime = +new Date();
            for (var i = 0; i < this.timers.length; i++) {
                if (!this.timers[i](this.currTime)) {
                    this.timers.splice(i, 1);
                    i--;
                }
            }
        }
        requestAnimationFrame(this.runNext.bind(this));
    };
    Timer.prototype.stop = function () {
        clearTimeout(this.timerId);
        this.timerId = 0;
    };
    return Timer;
}());
